# -*- coding: utf-8 -*-
# @Time : 2023/11/23 14:09
# @Author : 支晓光
# @Email : 1473858993@qq.com
# @File : parame_utils.py
# @Project : youguuUI
import csv
import os.path

import yaml
from openpyxl import load_workbook
from common.handler_path import xlsx_dir, yaml_dir, csv_dir


class DataUtil:

    def read_yaml_dict(self, filename):
        filepath = os.path.join(yaml_dir, filename)
        file = open(filepath, 'r+', encoding='utf8')
        data = yaml.safe_load(file.read())
        return data


    def read_csv(self, filename):
        filepath = os.path.join(csv_dir, filename)
        file = open(filepath, 'r+', encoding='utf8')
        data = csv.reader(file)
        l = []
        for line in data:
            l.append(line)
        l.pop(0)
        return l


class Excel_util:
    def __init__(self, filepath, sheetname):
        self.wb = load_workbook(filepath)
        self.sheet = self.wb[sheetname]

    def getdata(self):
        l = []
        for line in self.sheet:
            l1 = []
            l1.append(line[0].value)
            l1.append(line[1].value)
            l.append(l1)
        l.pop(0)
        return l


if __name__ == '__main__':
    filepath = os.path.join(xlsx_dir, 'excel.xlsx')
    dy = Excel_util(filepath, 'Sheet1')

    # 调试信息
    # print(dy.getdata())
    # print(DataUtil().read_csv('csv.csv'))
    # print(DataUtil().read_yaml_dict('yaml.yaml'))